add cache to endponits/publisher/build#5466
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds Redis caching to the get_snap_repo endpoint to improve performance by caching snap information for 1 hour, reducing redundant API calls to the dashboard service.
Key changes:
- Implements a cache-aside pattern using
redis_cachewith a 1-hour TTL - Follows the same caching approach as
webapp/endpoints/publisher/listing.py - Caches the result of
dashboard.get_snap_info()to avoid repeated API calls
| data = {"github_orgs": [], "github_repository": None, "github_user": None} | ||
|
|
||
| details = dashboard.get_snap_info(flask.session, snap_name) | ||
| snap_info_key = f"snap_info:{snap_name}" |
There was a problem hiding this comment.
The cache key construction is duplicated here and in webapp/endpoints/publisher/listing.py. Consider using the helper function get_snap_info_key() from listing.py to ensure consistency across the codebase. This could be extracted to a shared utility module or imported from listing.py.
| snap_info_key = f"snap_info:{snap_name}" | ||
| details = redis_cache.get(snap_info_key, expected_type=dict) | ||
| if not details: | ||
| details = dashboard.get_snap_info(flask.session, snap_name) | ||
| redis_cache.set(snap_info_key, details, ttl=3600) |
There was a problem hiding this comment.
Missing cache invalidation strategy. When snap metadata is updated (e.g., via webapp/endpoints/publisher/settings.py or webapp/publisher/snaps/release_views.py calling snap_metadata()), this cached snap info won't be invalidated, leading to stale data.
The webapp/endpoints/publisher/listing.py file shows the pattern: after successful snap_metadata() or snap_screenshots() calls, it invalidates the cache using redis_cache.delete(snap_info_key) (lines 200 and 217). Similar invalidation should be added to other files that modify snap metadata, or this cache implementation should be revisited.
909b823 to
debf35d
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5466 +/- ##
==========================================
- Coverage 66.80% 0 -66.81%
==========================================
Files 113 0 -113
Lines 3714 0 -3714
Branches 965 0 -965
==========================================
- Hits 2481 0 -2481
+ Misses 1098 0 -1098
+ Partials 135 0 -135 🚀 New features to boost your workflow:
|
Done
How to QA
Testing
Issue / Card
Fixes #
Screenshots